<%@page import="entities.Category"%>
<%@page import="entities.Link"%>
<%@page import="java.util.List"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%
List<Link> links = (List<Link>) request.getAttribute("links");
List<Category> categories = (List<Category>) request.getAttribute("categories");
String cid = (String) request.getAttribute("cid");
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/admin/layouts/header.jsp" />

<script type="text/javascript" src="/admin/js/custom/link_list.js"></script>
<script type="text/javascript">
<!--
var server = "<%=UrlHelper.getServerUrl(request)%>";
var cid = "<%=cid%>";
//-->
</script>		
					<!-- Content Area -->
                	<div id="da-content-area">
                		<jsp:include page="/admin/elements/message_box.jsp" />
                	
                		<div class="grid_4">
                        	<div class="da-panel collapsible">
                            	<div class="da-panel-header">
                                	<span class="da-panel-title">
                                        <img src="/admin/images/icons/black/16/list.png" alt="" />
                                        List Link
                                    </span>
                                    
                                </div>
                                <div class="da-panel-content">
                                	<div class="dataTables_wrapper" role="grid">
										
										<div class="dataTables_length">
											<label>Action
												<select name="action" class="action-value" size="1">
													<option value="status_active">Change to Status Active</option>
													<option value="status_pending">Change to Status Pending</option>
							                        <option value="status_inactive">Change to Status Inactive</option>
							                        <option value="delete">Delete all selected</option>
												</select>
												&nbsp;
												<input class="da-button gray apply-change" type="button" value="Change">
											</label>
										</div>
										
										<div class="dataTables_filter">
											<form method="get">
												<label>
													<select name="cid">
														<option value="">(TOP)</option>
														<%
														for (int i = 0; i < categories.size(); i++) {
														%>
														<option value="<%=categories.get(i).getId()%>">
															|<% for (int j = 2 ; j <= categories.get(i).getLevel(); j++) {%>&nbsp;&nbsp;|<% } %>___
															<%=categories.get(i).getName()%> (<%=categories.get(i).getLevel()%>)
														</option>
														<%
														}
														%>
													</select>
													
													<input class="da-button gray" type="submit" value="Change Category">
												</label>
											</form>
										</div>
										
										<table class="da-table list-table">
	                                        <thead>
	                                            <tr>
	                                            	<th><input type="checkbox" class="checkall" /></th>
	                                                <th>Id</th>
	                                                <th>Title</th>
	                                                <th>Category</th>
	                                                <th>Status</th>
	                                                <th>Type</th>
	                                                <th></th>
	                                            </tr>
	                                        </thead>
	                                        <tbody>
	                                        	<% for (int i = 0; i < links.size(); i++) { %>
	                                            <tr>
	                                            	<td><input type="checkbox"  value="<%=links.get(i).getId()%>" /></td>
	                                                <td><%=links.get(i).getId() %></td>
	                                                <td><%=links.get(i).getName() %></td>
	                                                <td><%=links.get(i).getCategory() %></td>
	                                                <td>
	                                                	<%
														switch (links.get(i).getStatus()) {
															case 0: 
																%>Inactive<%
																break;
															case 1:
																%>Pending<%
																break;
															case 2:
																%>Active<%
																break;
															default:
																break;
														}
														%>
	                                                </td>
	                                                <td><%=links.get(i).getType() %></td>
	                                                <td class="da-icon-column">
	                                                	<a href="/admin/link/edit/<%=links.get(i).getId()%>"><img src="/admin/images/icons/color/pencil.png" /></a>
	                                                	<a href="/admin/link/delete/<%=links.get(i).getId()%>" class="delete"><img src="/admin/images/icons/color/cross.png" /></a>
	                                                </td>
	                                            </tr>
	                                            <% } %>
	                                        </tbody>
	                                    </table>
										<div class="dataTables_paginate paging_full_numbers">
											<% if (prevPage) { %>
												<a class="previous paginate_button" href="<%=paginator.getPrev()%>">Previous</a>
											<% } else { %>
												<span class="previous paginate_button paginate_button_disabled" id="dyntable_previous">Previous</span>
											<% } %>
											<% if (nextPage) { %>
												<a class="next paginate_button"  href="<%=paginator.getNext()%>">Next</a>
											<% } else { %>
												<span class="next paginate_button paginate_button_disabled" id="dyntable_next">Next</span>
											<% } %>
										</div>
									</div>
                                </div>
                            </div>
                        </div>
                	</div>

<jsp:include page="/admin/layouts/footer.jsp" />